home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 4.1 KB | 158 lines | [TEXT/MPS ] |
- // PathGraph.cp
- // Copyright © 1992 Emergent Behavior. All rights reserved.
-
- #ifndef _PATHGRAPH_
- #include "PathGraph.h"
- #endif
-
- #ifndef _GAFAILURE_
- #include "GAFailure.h"
- #endif
-
- //==========================================================
- TPathGraph::TPathGraph( void )
- : fGrafPort( NIL ),
- fCityMap( NIL ),
- fPlotter( NIL )
- {
-
- }
- //----------------------------------------------------------
- TPathGraph::TPathGraph( const TPathGraph& sourcePathGraph )
- : fGrafPort( sourcePathGraph.fGrafPort ),
- fQDRect( sourcePathGraph.fQDRect ),
- fCityMap( sourcePathGraph.fCityMap ),
- fPlotter( sourcePathGraph.fPlotter )
- {
- }
- //----------------------------------------------------------
- TPathGraph::TPathGraph( const TCityMap& aCityMap, GrafPtr grafPort, Rect qdRect )
- : fGrafPort( grafPort ),
- fQDRect( qdRect ),
- fCityMap( (TCityMap*)&aCityMap )
- {
-
- Point* cityLocations = aCityMap.GetCityLocations();
- short largestDimension = this->FindLargestDimension( cityLocations );
- largestDimension +=10;
- HugeRect scaledRect( -largestDimension, largestDimension, largestDimension, -largestDimension );
- TPlotter* plotter = new TPlotter( &qdRect, &scaledRect, grafPort);
- FailNIL(plotter);
- fPlotter = plotter;
- }
- //----------------------------------------------------------
- TPathGraph::~TPathGraph( void )
- {
- delete fPlotter;
- }
-
- //----------------------------------------------------------
- TPathGraph*
- TPathGraph::Clone( void )
- {
- TPathGraph* copy = new TPathGraph(*this);
- FailNIL(copy);
- return copy;
- }
-
- //----------------------------------------------------------
- void
- TPathGraph::SetGrafPort( GrafPtr grafPort )
- {
- fGrafPort = grafPort;
- }
-
- //----------------------------------------------------------
- void
- TPathGraph::SetQDRect( Rect qdRect )
- {
- fQDRect = qdRect;
- }
-
- //----------------------------------------------------------
- void
- TPathGraph::PlotCityLocations( void )
- {
- short kPenHeight = 3;
- short kPenWidth = 3;
- TPen* aPen = new TPen( *fPlotter, blackColor );
- FailNIL(aPen);
- short numCities = fCityMap->GetNumberCities();
- Point* cityLocationArray = fCityMap->GetCityLocations();
-
- aPen->SetSize( kPenWidth, kPenHeight );
-
- for ( short cityIndex = 0; cityIndex < numCities; ++cityIndex )
- aPen->DotAt( cityLocationArray[ cityIndex ].h, cityLocationArray[ cityIndex ].v );
- delete aPen;
- }
- //----------------------------------------------------------
- void
- TPathGraph::PlotRoute( Importance* importanceArray )
- {
- TPen* aPen = new TPen( *fPlotter, redColor );
- FailNIL(aPen);
- short numCities = fCityMap->GetNumberCities();
- Point* cityLocationArray = fCityMap->GetCityLocations();
- Route theRoute = fCityMap->SortCities( importanceArray );
- City currentCity;
-
- currentCity =theRoute[ 0 ];
- aPen->Up();
- aPen->Goto( cityLocationArray[ currentCity ].h, cityLocationArray[ currentCity ].v );
-
- aPen->Down();
- for ( short cityIndex = 1; cityIndex < numCities; ++cityIndex )
- {
- currentCity =theRoute[ cityIndex ];
- aPen->Goto( cityLocationArray[ currentCity ].h, cityLocationArray[ currentCity ].v );
- }
-
- currentCity =theRoute[ 0 ];
- aPen->Goto( cityLocationArray[ currentCity ].h, cityLocationArray[ currentCity ].v );
-
-
- delete aPen;
- }
-
- //----------------------------------------------------------
- GrafPtr
- TPathGraph::GetGrafPort( void )
- {
- return fGrafPort;
- }
- //----------------------------------------------------------
- Rect
- TPathGraph::GetQDRect( void )
- {
- return fQDRect;
- }
- //----------------------------------------------------------
- TPlotter*
- TPathGraph::GetPlotter( void )
- {
- return fPlotter;
- }
- //----------------------------------------------------------
- short
- TPathGraph::FindLargestDimension( Point* cityLocationArray )
- {
- short numCities = fCityMap->GetNumberCities();
- short largestDimension = 0;
-
- for (short cityIndex = 0; cityIndex < numCities; ++cityIndex )
- {
- if (cityLocationArray[ cityIndex ].h > largestDimension)
- largestDimension = cityLocationArray[ cityIndex ].h;
- if (cityLocationArray[ cityIndex ].v > largestDimension)
- largestDimension = cityLocationArray[ cityIndex ].v;
- }
- return largestDimension;
- }
- //----------------------------------------------------------
- TCityMap*
- TPathGraph::GetCityMap( void )
- {
- return fCityMap;
- }
-